/*
This is the class LogicController which talks to the Game class and is called by the UI controller.
Notes:
-All methods are static so that GUI can call them.
-When data is passed for a piece the string is in the format PieceName,OwnerName,XCoord,YCoord, ZCoord
*/

import java.util.*;
import java.awt.*;

public class LogicController
{

	//Game currentGame = new Game();
	Game currentGame = null;
	Storage storage= new Storage();
	boolean loaded=false;
	int tm1,w1,j1,kc1,kd1,tm2,w2,j2,kc2,kd2;//used for calculating stats
        Piece previousPiece;
	public LogicController()
	{
		//newGame();
	}




	public ArrayList<String> makeMove(ArrayList<Point> MoveInfo1, ArrayList <Integer> MoveInfo2, ArrayList<Boolean> MoveInfo3, String PieceInfo)
	{
		String[] PieceData = PieceInfo.split(","); //The String "PieceInfo" should be passed with "," seperating the data pieces for a game Piece
		Piece currentPiece = new Piece("0","0","0","0");
		Move currentMove = new Move(MoveInfo1,MoveInfo2,MoveInfo3.get(0),MoveInfo3.get(1)); //Constructs a Move

		if(PieceData[0].equals("Checker"))//if the first string says Checker create a checker, otherwise create a King
		{
			//If the first player put the piece set the direction to 1
			if(currentGame.currentPlayer.equals(currentGame.players.get(0)))
			{
				currentPiece = new Checker(PieceData[1],PieceData[2],PieceData[3],PieceData[4],1);
			}
			else //else set direction to -1
			{
				currentPiece = new Checker(PieceData[1],PieceData[2],PieceData[3],PieceData[4],-1);
			}
		}
		else //If the piece wasnt a checker, then its a king
		{
			//If the first player put the piece set the direction to 1
			if(currentGame.currentPlayer.equals(currentGame.players.get(0)))
			{
				currentPiece = new King(PieceData[1],PieceData[2],PieceData[3],PieceData[4],1);
			}
			else //else set direction to -1
			{
				currentPiece = new King(PieceData[1],PieceData[2],PieceData[3],PieceData[4],-1);
			}
		}

	return currentGame.makeMove(currentMove,previousPiece);

	}

	public Boolean addPiece(String PieceInfo)
	{
		String[] PieceData = PieceInfo.split(","); //The String "PieceInfo" should be passed with "," seperating the data pieces for a game Piece
		int boardInt; //integer to hold the board number in
		char choice;
		Piece currentPiece = new Piece("0","0","0","0");
		Board board;
		//Takes the first character of the piece Name
		choice= PieceData[0].charAt(0);

		switch(choice) //Takes the Piece name from the first index of PieceData and creates a piece accordingly using the first letter
		  {
		   case 'C':case 'c':
				if(currentGame.currentPlayer.equals(currentGame.players.get(0)))
				{
					currentPiece = new Checker(PieceData[1],PieceData[2],PieceData[3],PieceData[4],1);
				}
				else
				{
				currentPiece = new Checker(PieceData[1],PieceData[2],PieceData[3],PieceData[4],-1);
				}
		   break;

		   case 'K':case'k':
				//If the first player put the piece set the direction to 1
				if(currentGame.currentPlayer.equals(currentGame.players.get(0)))
				{
					currentPiece = new King(PieceData[1],PieceData[2],PieceData[3],PieceData[4],1);
				}
				else //else set direction to -1
				{
					currentPiece = new King(PieceData[1],PieceData[2],PieceData[3],PieceData[4],-1);
				}
		   break;


		   case 'B':case'b':
				//If the first player put the piece set the direction to 1
				if(currentGame.currentPlayer.equals(currentGame.players.get(0)))
				{
					currentPiece = new BlockedZone(PieceData[1],PieceData[2],PieceData[3],PieceData[4],1);
				}
				else //else set direction to -1
				{
					currentPiece = new BlockedZone(PieceData[1],PieceData[2],PieceData[3],PieceData[4],-1);
				}
		   break;

		   case 'S':case 's':
				//If the first player put the piece set the direction to 1
				if(currentGame.currentPlayer.equals(currentGame.players.get(0)))
				{
					currentPiece = new SafeZone(PieceData[1],PieceData[2],PieceData[3],PieceData[4],1);
				}
				else //else set direction to -1
				{
					currentPiece = new SafeZone(PieceData[1],PieceData[2],PieceData[3],PieceData[4],-1);
				}

		   break;

		   case 'M': case 'm':
				//If the first player put the piece set the direction to 1
				if(currentGame.currentPlayer.equals(currentGame.players.get(0)))
				{
					currentPiece = new Mine(PieceData[1],PieceData[2],PieceData[3],PieceData[4],1);
				}
				else //else set direction to -1
				{
					currentPiece = new Mine(PieceData[1],PieceData[2],PieceData[3],PieceData[4],-1);
				}
		   break;

		   default:
		   break;

		  }

		boardInt = Integer.parseInt(PieceData[4]);
		board = currentGame.getBoard(boardInt);
		return currentGame.addPiece(currentPiece,board);

	}

	public Boolean addBoards(int NumberOfBoards, Dimension BoardSize)//essentially this method only passes data to the Game class and returns Game's output
	{
		return currentGame.addBoards(NumberOfBoards, BoardSize);

	}

	public ArrayList<String> getBoard(int BoardName) // PieceName,OwnerName,XCoord,YCoord, ZCoord
	{
		//LinkedList of Pieces to store the boardPieces into
		LinkedList<Piece> boardPieces;
		//ArrayList<String> that we will store the piece information into
		ArrayList<String> pieceInfo = new ArrayList<String>();
		String temp="";
		Point currentPoint=new Point();
		Board currentBoard=currentGame.getBoard(BoardName);
		for(int i=0; i<currentGame.boardsSize.width;i++)
		{
			for(int j=0; j<currentGame.boardsSize.height;j++)
			{
						currentPoint.setLocation(i,j);
						temp=currentBoard.getPieces(currentPoint).toString();
						if(!temp.equals("[]"))
						{
							boardPieces=currentBoard.getPieces(currentPoint);
							for(int k=0; k<boardPieces.size();k++)
							{
								temp=boardPieces.get(k).getClass().getName()+",";
								temp =temp+boardPieces.get(k).owner+",";
								temp= temp+boardPieces.get(k).location.x+",";
								temp=temp+boardPieces.get(k).location.y+",";
								temp=temp+boardPieces.get(k).location.board;
								pieceInfo.add(temp);
								temp="";

							}
						}


				}
			}



		//Delivers the ArrayList<String>
		return pieceInfo;
	}

	public  ArrayList<String> getMovablePieces()
	{
		//Array list of Pieces that we will store the Game->getMoveablePieces result into
		ArrayList<Piece> moveable;
		//temp string that we will use to setup an ArrayList<String>
		String temp;
		//The string we will use to store the moveablepieces in
		ArrayList<String> pieceInfo = new ArrayList<String>();
		//calls the Game class to get movable Pieces;
		moveable=currentGame.getMovablePieces();

		//Sets up and ArrayList<String> to be delivered
		for(int i=0; i<moveable.size();i++)
		{
			temp=moveable.get(i).getClass().getName()+",";
			temp =temp+moveable.get(i).owner+",";
			temp= temp+moveable.get(i).location.x+",";
			temp=temp+moveable.get(i).location.y+",";
			temp=temp+moveable.get(i).location.board;
			pieceInfo.add(temp);
			temp="";
		}
		//Deliver the ArrayList<String>
		return pieceInfo;
	}

	public ArrayList<String> getAvailableMoves(String PieceInfo)
	{
		System.out.println("LOGICCONTROLLER: getting available moves...");
		String[] PieceData = PieceInfo.split(","); //The String "PieceInfo" should be passed with "," seperating the data pieces for a game Piece
		Piece currentPiece;
		ArrayList<Move> availableMoves= new ArrayList<Move>();
		ArrayList<String> available=new ArrayList<String>();
		if(PieceData[0].equals("Checker")) // If the first string says checker create a checker, otherwise create a King
		{
			if(currentGame.currentPlayer.equals(currentGame.players.get(0)))
			{
				currentPiece = new Checker(PieceData[1],PieceData[2],PieceData[3],PieceData[4],1);
			}
			else
			{
				currentPiece = new Checker(PieceData[1],PieceData[2],PieceData[3],PieceData[4],-1);
			}

		}
		else
		{
			//If the first player put the piece set the direction to 1
			if(currentGame.currentPlayer.equals(currentGame.players.get(0)))
			{
				currentPiece = new King(PieceData[1],PieceData[2],PieceData[3],PieceData[4],1);
			}
			else //else set direction to -1
			{
				currentPiece = new King(PieceData[1],PieceData[2],PieceData[3],PieceData[4],-1);
			}
		}

		availableMoves = currentGame.getAvailableMoves(currentPiece); //passes the Piece to the Game class in order for the available moves to be delivered
                previousPiece = currentPiece;
		String temp="";
		//The following for loop sets up an ArrayList<String>  to be delivered
		for(int i =0; i<availableMoves.size();i++)
		{
			temp= temp+availableMoves.get(i).getLocations().get(availableMoves.get(i).getLocations().size()-1).x+",";
			temp= temp+availableMoves.get(i).getLocations().get(availableMoves.get(i).getLocations().size()-1).y+",";
			temp= temp+availableMoves.get(i).getLocations().get(availableMoves.get(i).getLocations().size()-1).board;
			available.add(temp);

			temp="";
		}
		//return the ArrayList<String> available
		return available;
	}

	public ArrayList<Integer> getPieceCounter()//Returns the piece count for Checkers,Kings,Mine,BlockedZones,Safezones in that order
	{
		return currentGame.getPieceCounter();
	}

	public Boolean coinToss(int PlayersChoice)//simulates a coin toss to determine who starts the game first
	{

		Random rand = new Random();
		int coin; //represents the coin that will be flipped
		coin = Math.abs(rand.nextInt()%2); // the coin is flipped 0=heads 1=tails

		if(coin==PlayersChoice) // If the flipped coin is the same as the players choice return true
		{
			currentGame.setPlayer(0);
			currentGame.setFirst(0);
			return true;
		}

		currentGame.setPlayer(1);
		currentGame.setFirst(1);
		return false; //If the player lost the coin toss, return false

	}

	String getFirstPlayer()
	{
		return currentGame.getFirst();
	}

	//randomly places pieces on the board
	public void randomizePlacement()
	{
		currentGame.randomizePlacement();
	}

	//resets the game
	public void newGame()
	{
		currentGame = new Game();
	}

	//creates a new player in the data base
	public Boolean savePlayer(String name, String password)
	{
		//if the user exists return false, otherwise create the user and return true
		if(storage.getUser(name)!=null)
		{
			return false;
		}
		Player currentPlayer= new Player(name);
		currentPlayer.setPassword(password);
		storage.createUser(currentPlayer);
		return true;
	}
	//checks to see if the player exists and if his/her password matches
	public Boolean authenticatePlayer(String name, String password)
	{
		if(storage.getUser(name) != null)
		{
		Player thisPlayer = storage.getUser(name);
		if(thisPlayer.getPassword().equals(password))
		{
			return true;
		}
		}
		return false;
	}
	//Sets the currentPlayers playing the game
	public void setGamePlayers(ArrayList<String> players)
	{
		
		System.out.println("LOGICCONTROLLER: setting players...");
		currentGame.players.add(storage.getUser(players.get(0)));
		currentGame.players.add(storage.getUser(players.get(1)));
		currentGame.sortedplayers = (ArrayList<Player>) currentGame.players.clone();
                Collections.sort(currentGame.sortedplayers);
		//this is called every time when a new game is starting
		// thus it is a good place to setup game start player stats
		//increment gamestotal and unfinished
		currentGame.players.get(0).stats.gamestotal += 1;
		currentGame.players.get(0).stats.unfinished += 1;
		currentGame.players.get(1).stats.gamestotal += 1;
		currentGame.players.get(1).stats.unfinished += 1;
		//saves all stats of the players
		storage.saveData();
		
	}
	
	//gets the current Players playing the game
	public ArrayList<String> getGamePlayers() {
		ArrayList<String> playernames = new ArrayList();
                for(Player player: currentGame.players)
                    playernames.add(player.getName());
		return playernames;
		
	}


	//returns all users
	public ArrayList<String> getUsers()
	{
		return storage.getUsers();
	}


//removes a player from the database
	public void deletePlayer(String player)
	{
		storage.deleteUser(player);
	}

//returns the stats of a player
	public ArrayList<Integer> getPlayerStats(String player)
	{
		if(storage.getUserStats(player) != null)
		return storage.getUserStats(player);
		return null;
	}


//deletes the stats of one player
	public void deletePlayerStats(String player)
	{
		storage.clearUserStats(player);
	}

	//deletes all stats
	public void deleteAllStats()
	{
		storage.clearAllStats();
	}
	//gets an arraylist of dates representing games that two players haveplayed with each other
	public ArrayList<Date> getGames(String player1,String player2)
	{
		ArrayList<String> players = new ArrayList<String>();
		players.add(player1);
		players.add(player2);
		return storage.getGames(players);
	}

	//returns the currentPlayer
	public String getGamePlayer()
	{
		return currentGame.currentPlayer.getName();
	}
	//loads a game

	public boolean loadGame(Date date,ArrayList<String> gamePlayers)
	{
		System.out.println("LOGICCONTROLLER: loading game...");
		//loaded=true;
		currentGame = storage.getGame(date, gamePlayers);
		
		if (currentGame == null){
			System.out.println("LOGICCONTROLLER: current game is null");
		}else{
			if (currentGame.currentPlayer == null){
				System.out.println("LOGICCONTROLLER: current player is null");
			}
			if (currentGame.players == null){
				System.out.println("LOGICCONTROLLER: players is null");
			}else if (currentGame.players.get(0) == null){
				System.out.println("LOGICCONTROLLER: current player is null");
			}
			if (currentGame.sortedplayers == null){
				System.out.println("LOGICCONTROLLER: sortedplayers is null");
			}
		}
		
		/*
		tmpsearch: for (int i=0; i<gamePlayers.size(); ++i){
			if (!gamePlayers.get(i).equals(currentGame.getFirst())){
				tmpsecond = storage.getUser(gamePlayers.get(i));
				break tmpsearch;
			}
		}
		if (tmpsecond == null){
			System.out.println("LOGICCONTROLLER: ...error temp second player still null");
		}
		//Since the game is loaded we need to save all the stats within the game
		//so we can calculate any new moves made by the player in the game.
		tm1=currentGame.tm1;
		w1=currentGame.w1;
		j1=currentGame.j1;
		kc1=currentGame.kc1;
		kd1=currentGame.kd1;
		tm2=currentGame.tm2;
		w2=currentGame.w2;
		j2=currentGame.j2;
		kc2=currentGame.kc2;
		kd2=currentGame.kd2;
		*/
		return true;
	}

	//saves the currentGame
	public boolean saveGame()
	{
		
		System.out.println("LOGICCONTROLLER: saving game...");
		
		if (currentGame == null){
			System.out.println("LOGICCONTROLLER: current game is null");
		}else{
			if (currentGame.currentPlayer == null){
				System.out.println("LOGICCONTROLLER: current player is null");
			}else if (currentGame.players == null){
				System.out.println("LOGICCONTROLLER: players is null");
			}else if (currentGame.players.get(0) == null){
				System.out.println("LOGICCONTROLLER: current player is null");
			}
		}
		//save game should not mess with user stats, it should only save the game
		/*
		if(loaded)
		{
			//updates the stats of all players
			//takes total moves of the current game and subtracts it from the total moves of the loaded game
			//which should be the total moves made since the game was loaded
			currentGame.players.get(0).stats.jumps+=(currentGame.j1-j1);
			currentGame.players.get(0).stats.kingscreated+=(currentGame.kc1-kc1);
			currentGame.players.get(0).stats.kingsdestroyed+=(currentGame.kd1-kd1);
			currentGame.players.get(0).stats.movestotal+=(currentGame.tm1-tm1);
			currentGame.players.get(0).stats.warps+=(currentGame.w1-w1);

			currentGame.players.get(1).stats.jumps+=(currentGame.j2-j2);
			currentGame.players.get(1).stats.kingscreated+=(currentGame.kc2-kc2);
			currentGame.players.get(1).stats.kingsdestroyed+=(currentGame.kd2-kd2);
			currentGame.players.get(1).stats.movestotal+=(currentGame.tm2-tm2);
			currentGame.players.get(1).stats.warps+=(currentGame.w2-w2);
		}

		if(!loaded)
		{
			//updates the stats of all players
			currentGame.players.get(0).stats.jumps+=currentGame.j1;
			currentGame.players.get(0).stats.kingscreated+=currentGame.kc1;
			currentGame.players.get(0).stats.kingsdestroyed+=currentGame.kd1;
			currentGame.players.get(0).stats.movestotal+=currentGame.tm1;
			currentGame.players.get(0).stats.warps+=currentGame.w1;

			currentGame.players.get(1).stats.jumps+=currentGame.j2;
			currentGame.players.get(1).stats.kingscreated+=currentGame.kc2;
			currentGame.players.get(1).stats.kingsdestroyed+=currentGame.kd2;
			currentGame.players.get(1).stats.movestotal+=currentGame.tm2;
			currentGame.players.get(1).stats.warps+=currentGame.w2;
			//if this game was not loaded previously add 1 to the total games being played by the player
			currentGame.players.get(0).stats.gamestotal+=1;
			currentGame.players.get(1).stats.gamestotal+=1;
		}
		storage.saveUsers();
		*/
		storage.saveGame(currentGame);
		return true;
	}
	
	//tells us when a game is finished so stats can be updated
	// 0=draw 1=player 1 wins 2=player 2 wins
	//nvm the above!
	//this will take the username of the player who lost the game
	// if the game was tied, the username will be empty
	public void finishGame(String loser)
	{
		//increment finished and decrement unfinished
		currentGame.players.get(0).stats.finished += 1;
		currentGame.players.get(0).stats.unfinished -= 1;
		currentGame.players.get(1).stats.finished += 1;
		currentGame.players.get(1).stats.unfinished -= 1;
		//save general gameplay stats
		currentGame.updateGameplayStats();
		//save game result stats
		if (loser.equals(currentGame.players.get(0).getName())){
			//1st player lost
			currentGame.players.get(0).stats.losses += 1;
			currentGame.players.get(1).stats.wins += 1;
		}else if (loser.equals(currentGame.players.get(1).getName())){
			//2nd player lost
			currentGame.players.get(1).stats.losses += 1;
			currentGame.players.get(0).stats.wins += 1;
		}else{
			//tie game
			currentGame.players.get(0).stats.draws += 1;
			currentGame.players.get(1).stats.draws += 1;
		}
		
		/*
		//updates the stats of all players
		currentGame.players.get(0).stats.finished+=1;
		currentGame.players.get(1).stats.finished+=1;
		if(!loaded)
		{
			currentGame.players.get(0).stats.jumps+=currentGame.j1;
			currentGame.players.get(0).stats.kingscreated+=currentGame.kc1;
			currentGame.players.get(0).stats.kingsdestroyed+=currentGame.kd1;
			currentGame.players.get(0).stats.movestotal+=currentGame.tm1;
			currentGame.players.get(0).stats.warps+=currentGame.w1;

			currentGame.players.get(1).stats.jumps+=currentGame.j2;
			currentGame.players.get(1).stats.kingscreated+=currentGame.kc2;
			currentGame.players.get(1).stats.kingsdestroyed+=currentGame.kd2;
			currentGame.players.get(1).stats.movestotal+=currentGame.tm2;
			currentGame.players.get(1).stats.warps+=currentGame.w2;
		}
		if(loaded)
		{
			//updates the stats of all players
			//takes total moves of the current game and subtracts it from the total moves of the loaded game
			//which should be the total moves made since the game was loaded
			currentGame.players.get(0).stats.jumps+=(currentGame.j1-j1);
			currentGame.players.get(0).stats.kingscreated+=(currentGame.kc1-kc1);
			currentGame.players.get(0).stats.kingsdestroyed+=(currentGame.kd1-kd1);
			currentGame.players.get(0).stats.movestotal+=(currentGame.tm1-tm1);
			currentGame.players.get(0).stats.warps+=(currentGame.w1-w1);

			currentGame.players.get(1).stats.jumps+=(currentGame.j2-j2);
			currentGame.players.get(1).stats.kingscreated+=(currentGame.kc2-kc2);
			currentGame.players.get(1).stats.kingsdestroyed+=(currentGame.kd2-kd2);
			currentGame.players.get(1).stats.movestotal+=(currentGame.tm2-tm2);
			currentGame.players.get(1).stats.warps+=(currentGame.w2-w2);

			storage.finishedGame(currentGame);//deletes the current game from saved games
		}
		if(result==1)//player one won
		{
			currentGame.players.get(0).stats.wins+=1;
			currentGame.players.get(1).stats.losses+=1;
		}
		if(result==2)//player two won
		{
			currentGame.players.get(1).stats.wins+=1;
			currentGame.players.get(0).stats.losses+=1;
		}
		if(result==0)//the game was a draw
		{
			currentGame.players.get(1).stats.draws+=1;
			currentGame.players.get(0).stats.draws+=1;
		}
		*/
		//saves all stats of the players
                currentGame.finished = true;
		storage.saveData();
	}

	//sets the initial boards within moveslog
	public void setIB()
	{
		currentGame.setInitialBoard();
	}
	//returns the moves log
	public MovesLog getMovesLog()
	{
		return currentGame.getMovesLog();
	}
	//gets the currentGame stats
	public ArrayList<ArrayList<Integer>> getStats()
	{
		if (currentGame != null){
			return currentGame.getStats();
		}else{
			return null;
		}
		
	}
	public Dimension getBoardSize()
	{
		return currentGame.boardsSize;
	}
	//tell Logic to get the list of moves stored for replays
	// returns a list of turns each of which has a list of moves defined as
	// { "mine_hit", "change_to_king", "initial_position", ["jumped_position" ... ] , "destination_position" }
	public ArrayList<ArrayList<ArrayList<String>>> getReplayMoves()
	{
		System.out.println("LOGICCONTROLLER: getting replay moves...");
		ArrayList<ArrayList<ArrayList<String>>> results = new ArrayList<ArrayList<ArrayList<String>>>();
		for (int t=0; t<currentGame.gameMoves.turns; ++t){
			ArrayList<ArrayList<String>> tempturnresults = new ArrayList<ArrayList<String>>();
			ArrayList<Move> tempturn = currentGame.gameMoves.getTurn(t);
			for (int m=0; m<tempturn.size(); ++m){
				ArrayList<String> tempmoveresults = new ArrayList<String>();
				Move tempmove = tempturn.get(m);
				tempmoveresults.add("" + tempmove.hitMine);
				tempmoveresults.add("" + tempmove.transformToKing);
				for (int l=0; l<tempmove.locations.size(); ++l){
					Location templocation = tempmove.locations.get(l);
					tempmoveresults.add("" + templocation.x + "," + templocation.y + "," + templocation.board);
				}
				tempturnresults.add(tempmoveresults);
			}
			results.add(tempturnresults);
		}
		/*
		String X,Y,Z;//used for saving positions
		for(int i=0;i<currentGame.gameMoves.turns;i++)
		{
			//For every turn we go through add ArrayList<ArrayList<String>> so we can fill them
			results.add(new ArrayList<ArrayList<String>>());
			results.get(i).add(new ArrayList<String>());

			for(int j=0;j<currentGame.gameMoves.getTurn(i).size();j++)
			{
				//checks to see if a mine was hit adds true to the ArrayList<String> if it did
				if(currentGame.gameMoves.getTurn(i).get(j).hitMine)
				{
					results.get(i).get(j).add("true");
				}
				else//false otherwise
				{
					results.get(i).get(j).add("false");
				}
				//Checks to see if a king was made
				if(currentGame.gameMoves.getTurn(i).get(j).transformToKing)
				{
					results.get(i).get(j).add("true");
				}
				else
				{
					results.get(i).get(j).add("false");
				}
				//adds the initial location
				X=""+currentGame.gameMoves.getTurn(i).get(j).getLocations().get(0).x;
				Y=""+currentGame.gameMoves.getTurn(i).get(j).getLocations().get(0).y;
				Z=""+currentGame.gameMoves.getTurn(i).get(j).getLocations().get(0).board;
				results.get(i).get(j).add(X+","+Y+","+Z);
				//if the location size is 3 there was a jump made
				if(currentGame.gameMoves.getTurn(i).get(j).getLocations().size()==3)
				{  //first set the jump location, and then the ending location
					X=""+currentGame.gameMoves.getTurn(i).get(j).getLocations().get(1).x;
					Y=""+currentGame.gameMoves.getTurn(i).get(j).getLocations().get(1).y;
					Z=""+currentGame.gameMoves.getTurn(i).get(j).getLocations().get(1).board;
					results.get(i).get(j).add(X+","+Y+","+Z);

					X=""+currentGame.gameMoves.getTurn(i).get(j).getLocations().get(2).x;
					Y=""+currentGame.gameMoves.getTurn(i).get(j).getLocations().get(2).y;
					Z=""+currentGame.gameMoves.getTurn(i).get(j).getLocations().get(2).board;
					results.get(i).get(j).add(X+","+Y+","+Z);
				}
				else
				{	//if no jump was made the end location will be found at index 1
					X=""+currentGame.gameMoves.getTurn(i).get(j).getLocations().get(1).x;
					Y=""+currentGame.gameMoves.getTurn(i).get(j).getLocations().get(1).y;
					Z=""+currentGame.gameMoves.getTurn(i).get(j).getLocations().get(1).board;
					results.get(i).get(j).add(X+","+Y+","+Z);
				}
			}
		}
		*/
		return results;//return the results
	}

	//tell Logic to get the initial board states stored for replays
	// returns a list of pieces as "PieceName,OwnerName,XCoord,YCoord,ZCoord"
	public ArrayList<String> getReplayBoards()
	{
		System.out.println("LOGICCONTROLLER: getting replay boards...");
		//LinkedList of Pieces to store the boardPieces into
		//LinkedList<Piece> boardPieces;
		//ArrayList<String> that we will store the piece information into
		ArrayList<String> pieceInfo = new ArrayList<String>();
		String temp="";
		//Point currentPoint=new Point();
		//Board currentBoard=currentGame.gameMoves.initialBoards.get(0);
		ArrayList<Board> refboards = currentGame.gameMoves.initialBoards;
		for (int b=0; b<refboards.size(); ++b){
			Board refboard = refboards.get(b);
			for (int x=0; x<refboard.size.width; ++x){
				for (int y=0; y<refboard.size.height; ++y){
					LinkedList<Piece> refpieces = refboard.getPieces(new Point(x,y));
					for (int p=0; p<refpieces.size(); ++p){
						Piece refpiece = refpieces.get(p);
						temp = refpiece.getClass().getName() + "," + refpiece.owner + "," + x + "," + y + "," + b;
						pieceInfo.add(temp);
					}
				}
			}
		}
		/*
		//get all pieces from the first board
		for(int i=0; i<currentGame.boardsSize.width;i++)
		{
			for(int j=0; j<currentGame.boardsSize.height;j++)
			{
						currentPoint.setLocation(i,j);
						temp=currentBoard.getPieces(currentPoint).toString();
						if(!temp.equals("[]"))
						{
							boardPieces=currentBoard.getPieces(currentPoint);
							for(int k=0; k<boardPieces.size();k++)
							{
								temp=boardPieces.get(k).getClass().getName()+",";
								temp =temp+boardPieces.get(k).owner+",";
								temp= temp+i+",";
								temp=temp+j+",";
								temp=temp+0;
								pieceInfo.add(temp);
								temp="";

							}
						}


				}

			currentBoard=currentGame.gameMoves.initialBoards.get(1);
			//get all pieces from the second board
			for(int j=0; j<currentGame.boardsSize.height;j++)
			{
						currentPoint.setLocation(i,j);
						temp=currentBoard.getPieces(currentPoint).toString();
						if(!temp.equals("[]"))
						{
							boardPieces=currentBoard.getPieces(currentPoint);
							for(int k=0; k<boardPieces.size();k++)
							{
								temp=boardPieces.get(k).getClass().getName()+",";
								temp =temp+boardPieces.get(k).owner+",";
								temp= temp+i+",";
								temp=temp+j+",";
								temp=temp+1;
								pieceInfo.add(temp);
								temp="";

							}
						}


			}
		}
		*/


		//Delivers the ArrayList<String>
		return pieceInfo;
	}
}
